package org.ainlolcat.ainscience.statistics.handlers.fitting;

import org.ainlolcat.ainscience.statistics.handlers.fitting.functions.ZeroBasedGaussFunction;
import org.apache.commons.math.FunctionEvaluationException;
import org.apache.log4j.Logger;

/**
 * @author ainlolcat
 *         Date: 10/12/13
 */
public class ZeroBasedGaussPeakFitting extends ZeroBasedPsvVoigtPeakFitting {
    private static Logger log = Logger.getLogger(ZeroBasedPsvVoigtPeakFitting.class);

    public ZeroBasedGaussPeakFitting(PeakFittingStatisticHandler peakFittingStatisticHandler) {
        super(peakFittingStatisticHandler);
        function = new ZeroBasedGaussFunction();
    }

    protected double[] initialGuess(double mean, double disp) throws FunctionEvaluationException {
        double[] initialguess1 = {
                1,                              //A
                Math.abs(disp),                 //w_G
                mean                            //x0
        };
        initialguess1[0] = 1/function.value(mean,initialguess1);
        return initialguess1;
    }

    @Override
    protected double getWidth(double[] result) {
        return result[1];
    }

    @Override
    protected boolean isPreApproxSupported() {
        return false;
    }
}
